package com.acme.bankapp.service.bank;

import com.acme.bankapp.domain.bank.Bank;
import com.acme.bankapp.domain.bank.Client;
import com.acme.bankapp.domain.bank.accounts.Account;
import com.acme.bankapp.domain.bank.accounts.CheckingAccount;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Julia on 25.11.2014.
 */
public class BankReport {
    public static int getNbOfCustomers(Bank bank){
        return bank.getClients().size();
    }

    public static int getNbOfAccounts(Bank bank){
        int accNumber = 0;
        for (Client client:bank.getClients())
            accNumber += client.getAccounts().size();
        return  accNumber;
    }

    public static int getBankCredit(Bank bank){
        int creditSum = 0;
        for (Client client:bank.getClients())
            for (Account acc: client.getAccounts())
                if (acc instanceof CheckingAccount)
                    creditSum += ((CheckingAccount) acc).getOverdraft();
        return  creditSum;
    }


    public static Map<Client, ArrayList<Account>> getCustomerAccount(Bank bank){
        Map<Client, ArrayList<Account>> mapClientAcc = new HashMap<Client, ArrayList<Account>>();
        for (Client client:bank.getClients())
            mapClientAcc.put(client, new ArrayList<Account>(client.getAccounts()));
        return  mapClientAcc;
    }

}
